package com.xnyzc.lhy.order.controller.dapi.driver;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.work.EPunchType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.param.commut.CommutRecordParam;
import com.xnyzc.lhy.order.service.work.IOaCommutRecordService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Description 打卡
 * @Author zhuyubin
 * @Date 2019-08-19 20:23
 **/
@RestController
@RequestMapping(value = "dapi/commutRecord")
public class OaDCommutRecordController {

    @Autowired
    private IOaCommutRecordService iOaCommutRecordService;

    @PostMapping(value = "commutRecord")
    public Rv commutRecord(@ApiParam(name = "commutRecordParam", value = "打卡入参") @RequestBody CommutRecordParam commutRecordParam){
        Long userId = TokenUtil.getTokenUserId();
        String userType = TokenUtil.getUserType();
        String tag = TokenUtil.getTag();
        if (CheckUtil.objIsEmpty(userType, tag)){
            throw PangException.create(EErrorCode.missingAuthArgs);
        }
        Integer punchType = commutRecordParam.getPunchType();
        String punchAddress = commutRecordParam.getPunchAddress();
        String punchLng = commutRecordParam.getPunchLng();
        String punchLat = commutRecordParam.getPunchLat();
        /*if (CheckUtil.objIsEmpty(punchType, punchAddress, punchLng, punchLat)){
            throw PangException.create(EErrorCode.missingArg);
        }*/
        iOaCommutRecordService.commutRecord(userId, Integer.valueOf(userType), tag, punchType, punchAddress, punchLng, punchLat);
        if (EPunchType.goToWork.getType().equals(punchType)){
            return Rv.wrap(EErrorCode.success, EPunchType.goToWork.getDesc(), new HashMap<>(16));
        } else {
            return Rv.wrap(EErrorCode.success, EPunchType.offWork.getDesc(), new HashMap<>(16));
        }

    }
}
